package com.emspost.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TagFileParser {

    public static List<String[]> parseTagFile(String filePath) throws IOException {
        List<String[]> result = new ArrayList<>();
        Pattern pattern = Pattern.compile("^(.*?),tag=>(.*?)$"); // 正则表达式匹配模式

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                line = line.trim(); // 去除前后空格
                if (line.isEmpty()) {
                    continue; // 跳过空行
                }

                Matcher matcher = pattern.matcher(line);
                if (matcher.matches()) {
                    String jsonStr = matcher.group(1).trim();
                    String tag = matcher.group(2).trim();
                    result.add(new String[]{jsonStr, tag});
                } else {
                    System.out.println("补推数据解析ERROR数据" + line);
                }
            }
        }

        return result;
    }

    // 测试方法
    public static void main(String[] args) {
        String filePath = "C:\\Users\\Administrator\\Desktop\\mqakerr_data.txt"; // 替换为你的文件路径
        try {
            List<String[]> parsedData = parseTagFile(filePath);
            int send = 0;
            // 打印解析结果
            for (String[] entry : parsedData) {
                send++;
                System.out.println("当前执行条数"+ send +"/" + parsedData.size());
            }

        } catch (IOException e) {
            System.err.println("文件读取失败: " + e.getMessage());
        }
    }
}